package com.gitee.ed.arithmetic.leetcode.question.question_1_100.question_1_10;

import com.gitee.ed.arithmetic.leetcode.SolutionRunner;
import com.gitee.ed.arithmetic.leetcode.common.Question;
import com.gitee.ed.arithmetic.leetcode.solution.solution_1_100.solution_1_10.Solution7;

/**
 * @author hongda.li
 */
public class Question7 implements Question<Solution7> {
    @Override
    public String link() {
        return "https://leetcode.cn/problems/reverse-integer/description/";
    }

    @Override
    public String title() {
        return "7.整数反转";
    }

    @Override
    public String description() {
        return """
                给你一个 32 位的有符号整数 x ，返回将 x 中的数字部分反转后的结果。
                如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1] ，就返回 0。
                假设环境不允许存储 64 位整数（有符号或无符号）。
                """;
    }

    @Override
    public void test(Solution7 solution) {
        this.test1(solution);

        this.test2(solution);

        this.test3(solution);

        this.test4(solution);

        this.test5(solution);
    }

    private void test1(Solution7 solution) {
        SolutionRunner.checkString(321, solution.reverse(123));
    }

    private void test2(Solution7 solution) {
        SolutionRunner.checkString(-321, solution.reverse(-123));
    }

    private void test3(Solution7 solution) {
        SolutionRunner.checkString(21, solution.reverse(120));
    }

    private void test4(Solution7 solution) {
        SolutionRunner.checkString(0, solution.reverse(0));
    }

    private void test5(Solution7 solution) {
        SolutionRunner.checkString(109, solution.reverse(901000));
    }
}
